<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item label="申请人" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="使用日期" prop="usageDate">
        <el-date-picker
          v-model="queryParams.usageDate"
          type="date"
          placeholder="选择日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table ref="tables" v-loading="loading" :data="list" :height="tableHeight">
      <el-table-column label="申请人" align="center" prop="createBy" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="会议室名称" align="center" prop="roomName" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="地点" align="center" prop="address" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="会议说明" align="center" prop="description" min-width="150" :show-overflow-tooltip="true" />
      <el-table-column label="使用日期" align="center" prop="usageDate" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="使用时间" align="center" prop="browser" width="150" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          {{ scope.row.usageStartTime }}-{{ scope.row.usageEndTime }}
        </template>
      </el-table-column>

      <el-table-column label="审批说明" align="center" prop="remark" min-width="150" :show-overflow-tooltip="true"/>
      <!-- <el-table-column label="登录日期" align="center" prop="loginTime">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.loginTime) }}</span>
                </template>
            </el-table-column> -->
      <el-table-column label="操作" align="center" prop="loginTime" width="180" fixed="right">
        <template slot-scope="scope">
          <template v-if="scope.row.auditStatus == '0'">
            <el-button
              size="mini"
              type="text"
              @click="onShow(1, scope.row)"
              v-hasPermi="['approval:reserve:pass']"
              >通过</el-button
            >
            <el-button
              size="mini"
              type="text"
              style="color: red"
              @click="onShow(2, scope.row)"
              v-hasPermi="['approval:reserve:refuse']"
              >拒绝</el-button
            >
          </template>
          <span
            style="color: #1890ff; font-size: 12px"
            v-if="scope.row.auditStatus == '1'"
          >
            已通过
          </span>
          <span
            style="color: red; font-size: 12px"
            v-if="scope.row.auditStatus == '2'"
          >
            已拒绝
          </span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog
      :title="`审批说明`"
      :visible.sync="dialogVisible"
      width="400px"
    >
      <el-form>
        <el-form-item
          :label="`${passParams.type == 1 ? '通过' : '拒绝'}说明`"
          prop="status"
        >
          <el-input
            v-model.trim="passParams.remark"
            placeholder="请填写"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button
          type="primary"
          @click="onSure"
          :loading="saveLoading"
          :disabled="!passParams.remark"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { list, audit } from "@/api/approval/reserve";
export default {
  data() {
    return {
      queryParams: {
        createBy: "",
        usageDate: "",
        pageNum: 1,
        pageSize: 10,
        orderByColumn:'updateTime',
        isAsc: 'desc',
        // orderByColumn:'auditStatus',
        // isAsc: 'asc',
      },
      list: [],
      loading: false,
      total: 0,
      dialogVisible: false,
      passParams: {
        type: "",
        remark: "",
        id: "",
      },
      saveLoading: false,
    };
  },
  computed:{
    tableHeight () {
      return this.$store.state.app.clientHeight
    }
  },
  methods: {
    /** 拒接或者通过 */
    async onSure() {
      try {
        this.saveLoading = true;
        await audit({
          auditStatus: this.passParams.type,
          ...this.passParams,
        }).then((res) => {
          this.$message.success("保存成功");
          this.saveLoading = false
        });
        this.dialogVisible = false;
        this.getList();
      } catch (err) {
        this.saveLoading = false;
      }
    },
    onShow(type, row) {
      this.dialogVisible = true;
      this.passParams.type = type;
      this.passParams.remark = "";
      this.passParams.id = row.id;
    },
    /** 查询菜单列表 */
    getList() {
      this.loading = true;
      list(this.queryParams).then((res) => {
        this.list = res.rows;
        this.loading = false;
        this.total = res.total;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
  mounted() {
    this.getList();
  },
};
</script>

<style></style>
